/**
 * 认证相关 API
 */

import { get, post, put } from '@/utils/request'
import type {
  LoginRequest,
  LoginResponse,
  ChangePasswordRequest,
  RefreshTokenRequest,
  RefreshTokenResponse,
  User,
} from '@/types'

/**
 * 登录
 */
export function login(data: LoginRequest): Promise<LoginResponse> {
  return post<LoginResponse>('/api/Auth/login', data)
}

/**
 * 登出
 */
export function logout(): Promise<void> {
  return post<void>('/api/Auth/logout')
}

/**
 * 获取当前用户信息
 */
export function getCurrentUser(): Promise<User> {
  return get<User>('/api/Auth/me')
}

/**
 * 修改密码
 */
export function changePassword(data: ChangePasswordRequest): Promise<void> {
  return put<void>('/api/Auth/change-password', data)
}

/**
 * 刷新 Token
 */
export function refreshToken(data: RefreshTokenRequest): Promise<RefreshTokenResponse> {
  return post<RefreshTokenResponse>('/api/Auth/refresh', data)
}
